package com.summer.shopping.chat.handler;

import com.summer.shopping.chat.UserChatPool;
import com.summer.shopping.chat.WSInfo;
import com.summer.shopping.enums.chat.ChatInfoTypeConstant;
import com.summer.shopping.utils.WSUtils;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ConsoleLogHandler implements WSInfoTypeHandler{
    @Autowired
    UserChatPool chatPool;


    @SneakyThrows
    @Override
    public Object handleInfo(WSInfo.Standard info) {
        info.setContent(chatPool.getInfo().toString());
        info.setType(ChatInfoTypeConstant.CONSOLE);
        Long me = info.getFrom();
        chatPool.getSession(me).sendMessage(WSUtils.toTextMessage(info));
        return null;
    }
    @Override
    public boolean isSupport(String type) {
        return type.equals(ChatInfoTypeConstant.CONSOLE);
    }
}
